/** SKU相关服务 */

/**
 * [获取毛料批发列表]
 * @param  {[type]} pageNo   [页码]
 * @param  {[type]} pageSize [每页记录数]
 * @return {[type]}          [description]
 */
function materialList(pageNo,pageSize,callback){
  wx.request({
    url: getApp().globalData.host + 'material/list',
    header: getApp().globalData.header,
    data: { pageIndex: pageNo,pageSize:pageSize},
    method: 'POST',
    success: function (res) {
      if (typeof (res.data.records) != 'undefined' && res.data.records.length > 0) {
        for(let i = 0;i<res.data.records.length;i++){
          if(typeof(res.data.records[i].imgUrl)!='undefined'&&res.data.records[i].imgUrl.indexOf('img/')<2){ //处理图片兼容性
            res.data.records[i].imgUrl = getApp().globalData.imgHost + res.data.records[i].imgUrl;
          }
        }
        callback(res.data.records);
      }
    }
  })
}

/**
 * [根据查询条件查询SKU列表]
 * @param  {[type]}   url      [查询条件]
 * @param  {Function} callback [回调参数]
 * @return {[type]}            [SKU列表]
 */
function listQuery(url,callback){
  wx.request({
    url: getApp().globalData.host + url,
    header: getApp().globalData.header,
    method: 'POST',
    success: function (res) {
      if (typeof (res.data.records) != 'undefined' && res.data.records.length > 0) {
        for(let i = 0;i<res.data.records.length;i++){
          if(typeof(res.data.records[i].imgUrl)!='undefined'&&res.data.records[i].imgUrl.indexOf('img/')<2){ //处理图片兼容性
            res.data.records[i].imgUrl = getApp().globalData.imgHost + res.data.records[i].imgUrl;
          }
        }
        callback(res.data.records);
      }
    }
  })
}

module.exports = {
  materialList: materialList,
  listQuery:listQuery
}